import React, { useContext, useState, createContext } from 'react'

const GlobalContext = createContext();

export const GlobalProvider = ({ children }) => {
  const [userId, setUserId] = useState(null);
  const [persongListrefresh, setPerSonglistRefresh] = useState(false);
  const [favsongListrefresh, setFavSonglistRefresh] = useState(false);
  const [favsongrefresh, setFavsongRefresh] = useState(false);
  const [playerlistfresh, setPlayerlistRefresh] = useState(false);
  const [currentIndex, setCurrentIndex] = useState(0);
  const [playingDatalength, setPlayingDatalength] = useState(0);
  return (
    <GlobalContext.Provider value={{
      userId, setUserId,
      persongListrefresh, setPerSonglistRefresh,
      favsongrefresh, setFavsongRefresh,
      playerlistfresh, setPlayerlistRefresh,
      currentIndex, setCurrentIndex,
      playingDatalength, setPlayingDatalength,
      favsongListrefresh, setFavSonglistRefresh
    }}>
      {children}
    </GlobalContext.Provider>
  )
}
export const useGlobalContext = () => {
  return useContext(GlobalContext);
}
